Skip to content

Refactor CMake preset parser to own module - #621

Merged
nikobockerman merged 1 commit into
mainfrom
refactor-cmake-preset-parser-to-separate-module
Jul 21, 2026
Merged

Refactor CMake preset parser to own module#621
nikobockerman merged 1 commit into
mainfrom
refactor-cmake-preset-parser-to-separate-module

Conversation

@nikobockerman

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings July 21, 2026 04:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extracts the CMake preset parsing logic used by the C++ solver into a dedicated aoc_main._cmake_presets module, and adds unit tests to validate the preset lookup and inheritance behavior.

Changes:

  • Added aoc_main._cmake_presets as a minimal CMake preset reader (workflow configure-step lookup + binaryDir resolution with inheritance).
  • Refactored the C++ solver’s CMake config resolver to delegate preset parsing/queries to the new module.
  • Added a pytest suite covering preset resolution and error cases.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
aoc-main/tests/test_cmake_presets.py Adds unit tests for workflow/configure preset lookups and binaryDir inheritance behavior.
aoc-main/src/aoc_main/_solver_cpp.py Removes inline JSON parsing and delegates preset parsing to aoc_main._cmake_presets.
aoc-main/src/aoc_main/_cmake_presets.py Introduces the new preset parsing module used by the C++ solver.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread aoc-main/src/aoc_main/_solver_cpp.py
Comment thread aoc-main/src/aoc_main/_cmake_presets.py
Comment thread aoc-main/src/aoc_main/_cmake_presets.py
Comment thread aoc-main/src/aoc_main/_cmake_presets.py
Comment thread aoc-main/src/aoc_main/_cmake_presets.py
Copilot AI review requested due to automatic review settings July 21, 2026 20:52
@nikobockerman
nikobockerman force-pushed the refactor-cmake-preset-parser-to-separate-module branch from a2b7a1e to 1b1523d Compare July 21, 2026 20:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (2)

aoc-main/src/aoc_main/_solver_cpp.py:12

  • pathlib (and Iterable) are only imported under TYPE_CHECKING, but this module uses them in runtime-evaluated type annotations (there is no from __future__ import annotations), which will raise NameError at import time. Import them at runtime (or add from __future__ import annotations).
import asyncio
import os
from dataclasses import dataclass
from functools import cached_property
from typing import TYPE_CHECKING

from aoc_main import _cmake_presets, _logging, _solvers, _types

if TYPE_CHECKING:
    import pathlib
    from collections.abc import Iterable

aoc-main/src/aoc_main/_cmake_presets.py:116

  • binary_dir() can loop forever if presets contain an inheritance cycle (or repeated parents). Track visited preset names while walking the breadth-first inheritance graph so lookup always terminates with a clear error.
        pending = [configure_preset_name]
        while pending:
            name = pending.pop(0)
            preset = self._get_preset("configure", name)
            if preset is None:
                msg = f"Configure preset not found: {name}"
                raise CMakePresetError(msg)

            binary_dir = preset.get("binaryDir")
            if binary_dir is not None:
                _logger.debug("Found binaryDir from preset %s: %s", name, binary_dir)
                return pathlib.Path(binary_dir)

            _logger.debug(
                "binaryDir not set on preset %s; checking inherited presets", name
            )
            pending.extend(preset.get("inherits", []))

@nikobockerman
nikobockerman merged commit 5e82ba6 into main Jul 21, 2026
53 checks passed
@nikobockerman
nikobockerman deleted the refactor-cmake-preset-parser-to-separate-module branch July 21, 2026 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants